package test.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 文件赋值以及异常处理
 * User: cp
 * Date: 2023-11-21
 * Time: 10:00
 */
public class FileCopy {
    public static void main(String[] args) {
        //复制C:\\Javacaode2\\a.txt 到C:\\Javacode2\\b.txt
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream("C:\\Users\\86184\\Pictures\\Saved Pictures\\ASCII表.png");
            fileOutputStream = new FileOutputStream("C:\\Users\\86184\\Pictures\\Saved Pictures\\ASCII1111表.png", true);
            int i;
            while((i = fileInputStream.read()) != -1){
                fileOutputStream.write(i);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(fileInputStream != null){
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }finally {
                    fileInputStream = null;
                }
            }

            if(fileOutputStream != null){
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }finally {
                    fileOutputStream = null;
                }
            }
        }

        System.out.println("复制完成");

    }
}
